#include "Controls.h"
#include "SFML\Window.hpp"
#include <exception>

std::vector<std::vector<int>> CControls::_controls;

CControls::CControls(void){}
CControls::~CControls(void){}

void CControls::initialize(unsigned int players)
{
	_controls.resize(players);

	for (auto it = _controls.begin(); it != _controls.end(); it++)
	{
		(*it).resize(CTRL_SIZE);
	}

	// TODO: read controls from file
	_controls[0][CTRL_JUMP]					= sf::Keyboard::Space;
	_controls[0][CTRL_UP]					= sf::Keyboard::Up;
	_controls[0][CTRL_DOWN]					= sf::Keyboard::Down;
	_controls[0][CTRL_LEFT]					= sf::Keyboard::Left;
	_controls[0][CTRL_RIGHT]				= sf::Keyboard::Right;
	_controls[0][CTRL_SHOOT]				= sf::Keyboard::X;
	_controls[0][CTRL_SHOOT_2]				= sf::Keyboard::C;
	_controls[0][CTRL_DASH]					= sf::Keyboard::LControl;
	_controls[0][CTRL_SWITCH_WEAPON_LEFT]	= sf::Keyboard::Q;
	_controls[0][CTRL_SWITCH_WEAPON_RIGHT]	= sf::Keyboard::W;
	for (unsigned int i = 0; i < CTRL_SIZE; i++)
	{
		_controls[1][i] = sf::Keyboard::KeyCount;
	}
}

int CControls::Key(unsigned int key, unsigned int player)
{
	if (key < 0 || key > CTRL_SIZE - 1)
	{
		throw std::exception("Key index out of bound.");
		return 0;
	}

	if (player < 0 || player > _controls.size() - 1)
	{
		throw std::exception("Player index out of bound.");
		return 0;
	}

	return _controls[player][key];
}

